<template>
  <template v-for="item of option">
    <info-title>{{ item.title }}</info-title>
    <descriptions-group :columns="item.columns" :data-source="details" />
  </template>
</template>

<script>
import InfoTitle from '@gis/lib/components/splitter/info-title.vue';
import DescriptionsGroup from '@gis/lib/components/descriptions/index.vue';
import { unitDetail } from '@gis/lib/api';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';

export default {
  name: 'unit-details',
  props: {
    data: { type: Object, default: () => ({}) },
  },
  components: { InfoTitle, DescriptionsGroup },
  data() {
    return {
      details: {},
      option: [
        {
          title: '必填项',
          columns: [
            { label: '单位名称', key: 'name' },
            { label: '经营人', key: 'person' },
            { label: '手机号', key: 'phone' },
            { label: '主体业态', key: 'format_name' },
            { label: '所在网格', key: 'community_area_name' },
            {
              label: '证照类型',
              key: 'certificate_nature',
              format: (v) => ({ 1: '有证有照', 2: '有照无证', 3: '无证无照' }[v]),
            },
            { label: '地址', key: 'business_address' },
            { label: '简介', key: 'remark' },
          ],
        },
        {
          title: '基础信息',
          columns: [
            { label: '法人姓名', key: 'legal_person' },
            { label: '统一社会信用代码', key: 'social_credit_code' },
            {
              label: '主体工商备案状态',
              key: 'business_filing_status',
              format: (v) => ({ 0: '注销', 1: '存活', 2: '吊销', 3: '取缔', 4: '其他减少' }[v]),
            },
            { label: '许可证类型', key: 'license_name' },
            { label: '许可证备案号', key: 'license_num' },
            { label: '有效期', key: 'licenseTime' },
            {
              label: '许可证状态',
              key: 'license_status',
              format: (v) =>
                ({
                  0: '过期',
                  1: '有效',
                  2: '被撤销',
                  3: '被吊销',
                  4: '被撤回',
                  5: '注销',
                }[v]),
            },
          ],
        },
        {
          title: '负责人信息',
          columns: [
            { label: '身份证号', key: 'identity_num' },
            { label: '住所', key: 'residence' },
          ],
        },
        {
          title: '经营信息',
          columns: [
            { label: '经营面积', key: 'operating_area' },
            { label: '从业人数', key: 'employee_num' },
            {
              label: '营业状态',
              key: 'business_status',
              format: (v) => ({ 0: '停止营业', 1: '正常营业', 2: '间断营业' }[v]),
            },
            {
              label: '是否经营医疗器械',
              key: 'has_equipment',
              format: (v) => ({ 0: '否', 1: '是' }[v]),
            },
            { label: '医疗器械许可证', key: 'equip_license_num' },
            { label: '计量设备类型', key: 'format_name' },
            { label: '特种设备设备类型', key: 'unit_address' },
          ],
        },
        {
          title: '责任落实',
          columns: [
            { label: '管辖社区', key: 'community_area_name', colSpan: 24 },
            {
              label: '监督人员',
              key: 'supervisor_name',
              format: (v) => (v === '请选择监督人员' ? '' : v),
            },
            {
              label: '网格信息员',
              key: 'grid_member_name',
              format: (v) => (v === '请选择网格信息员' ? '' : v),
            },
            { label: '第一负责人', key: 'first_head' },
            { label: '联系方式', key: 'first_head_phone' },
            { label: '管理人员', key: 'manager' },
            { label: '联系方式', key: 'manager_phone' },
          ],
        },
      ],
    };
  },
  created() {
    this.getDataAsync();
  },
  methods: {
    async getDataAsync() {
      const data = await handleCommonRes(unitDetail({ id: this.data.id }));
      this.details = data;
    },
  },
};
</script>

<style scoped></style>
